home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programmer Power Tools
/
Programmer Power Tools.iso
/
microcrn
/
issue_32.arc
/
86WORLD.FIG
next >
Wrap
Text File
|
1979-12-31
|
4KB
|
178 lines
<<86 figure 1 - GetEnvironment for Pascal >>
CONST string128 = string[128];
{----------------------- GetEnvironment ----------------------}
{ return the value of the Environment Variable 'EnvVar' }
{-------------------------------------------------------------}
FUNCTION GetEnvironment (EnvVar : String128) : String128;
CONST
NULL = ^@;
VAR
EnvPtr : ^CHAR;
EnvSeg : INTEGER ABSOLUTE CSEG:$2C;
EnvOfs : INTEGER;
Found : BOOLEAN;
TmpStr, MatchStr : String128;
begin
TmpStr := '';
EnvOfs := 0;
EnvPtr := Ptr(EnvSeg, EnvOfs);
Found := FALSE;
WHILE (EnvPtr^ <> NULL) AND (NOT Found) DO
{ check for match of current variable name }
begin
MatchStr := '';
WHILE (EnvPtr^ <> NULL) DO
{ extract an environment variable name and its value }
begin
MatchStr := MatchStr + EnvPtr^;
EnvOfs := EnvOfs+1;
EnvPtr := Ptr(EnvSeg, EnvOfs);
end;
IF (EnvVar = Copy (MatchStr, 1, POS('=',MatchStr)-1)) THEN
{ Found the variable, get its value to return }
begin
TmpStr := COPY(MatchStr, POS('=',MatchStr)+1, Length(MatchStr));
Found := TRUE;
end { if variable found }
ELSE
{ Not Found, move past NULL to next variable }
begin
EnvOfs := EnvOfs+1;
EnvPtr := Ptr(EnvSeg,EnvOfs);
end; { variable not found }
end; { while not found and not end of environment }
GetEnvironment := TmpStr; { transfer result into return variable }
end; { GetEnvironment }
<<86 figure 2 - GetEnvironment for assembly language >>
;
; GetEnvironment- return a pointer to the value of a string
; in the MSDOS "Environment"
;
; ENTRY: DS:SI --> a string (in Pascal Format) containing var. name
;
; EXIT: IF (NC) ES:DI --> the value of said variable
; IF (C) nothing (not found)
ENVSEG equ word ptr cs:2Ch ;ptr to environment in base page
GetEnvironment PROC Near
PUSH AX
PUSH CX
PUSH SI
MOV ES,ENVSEG
XOR DI,DI
XOR AX,AX
CMP ES:[DI],AL ;see if no environment at all
JZ GetEnv9
GetEnv1:
POP SI ;retrieve string address
PUSH SI
MOV CL,[SI]
XOR CH,CH
INC SI
REPE CMPSB ;try to match
JNZ GetEnv2
CMP ES:byte ptr [DI],'='
JZ GetEnv3 ;FOUND
GetEnv2:
MOV CX,0FFFFh ;NOT FOUND
REPNZ SCASB ;scan until 0
CMP ES:[DI],AL
JZ GetEnv9 ;if double 0 then end of environment
JMP GetEnv1 ;else try next one
GetEnv3:
INC DI ;point past '='
STC ;indicate FOUND
GetEnv9:
POP SI
POP CX
POP AX
CMC
RET
GetEnvironment ENDP
<<86 figure 3 - new FINDCOMSPEC for assembly language Exec >>
COMSPECSTR DB 7,'COMSPEC'
FINDCOMSPEC:
PUSH SI
MOV PATHOFS,offset DEFPATH ;set up default
MOV PATHSEG,DS
MOV SI,offset COMSPECSTR
CALL GetEnvironment
JC FINDCOMSPEC9
MOV PATHOFS,DI ;found
MOV PATHSEG,ES
FINDCOMSPEC9:
POP SI
RET
<<86 figure 4 - new TESTEXEC to test modified EXEC >>
;
; TESTEXEC.ASM - test the new exec procedure
;
; This program MUST be made into a .COM file:
;
; masm testexec;
; link testexec+asmexec;
; exe2bin testexec
; ren testexec.bin testexec.com
; erase testexec.exe
;
EXTRN Exec:NEAR
Code segment byte public 'CODE'
assume cs:code,ds:code
org 100h
TESTEXEC:
MOV SP,8000h
MOV BX,800h ;request 32k even though we'll never need it
MOV AH,4Ah ;actually we are 'freeing' all but 32k
INT 21h
MOV SI,80h ;execute the command trailer
CALL EXEC ;in the base page (CS:80h)
MOV AH,4Ch ;(since this is a COM, CS==DS)
INT 21h
Code ENDS
end TESTEXEC
((This is 86world figure A.))
DB 'M2LIB=C:\M2\LIB',0
DB 'PATH=C:\;C:\BIN;\',0
DB 'CLUB=Sierra',0
DB 'NEIGHBORHOOD=Watts'
.
.
DB 0
((this is 86 Fig. B))
ComFile := '\command.com'+chr(0);
((this is 86 Fig C))
ComFile := GetEnvironment('COMSPEC')
+chr(0);